﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>工序信息库</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
    <script type="text/html" id="barDemo">
        <a title="修改" href="javascript:;" lay-event="edit" id="frmEdit"><i class="layui-icon">&#xe642;</i></a>
        <a title="人员配置" href="javascript:;" lay-event="setu" id="frmSetuser"><i class="layui-icon">&#xe656;</i></a>
        <a title="删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>

    </script>
    <script type="text/html" id="switch">
        <input type="checkbox" name="leader" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭" id="leader" dataId ={{ d.cCode }} value={{ d.leader }}  {{ d.leader=='1'? 'checked' : ''}}>
    </script>
</head>
<body>
    <div class="layui-fluid">
        <div id="bDiv">
        </div>
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">

                            <div class="layui-inline layui-show-xs-block" >
                                <input type="text" name="cCode" placeholder="工序编码" autocomplete="off" class="layui-input" id="cCode">
                                <input type="hidden" name="id" id="id">
                                <input type="hidden" name="cType" id="cType" value="GX" />
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="cName" placeholder="工序名称" autocomplete="off" class="layui-input" id="cName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="cMemo" placeholder="备注说明" autocomplete="off" class="layui-input" id="cMemo">
                            </div>
                         
                    
                        </form>
                    </div>


                    <div class="layui-card-body" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    var cType = "";
    var menuCode = "";
    $(function () {
        menuCode = getUrlVariable("menuCode");
        BannerData(menuCode, "bDiv");
        loadData();
    })
    var currPage = 1;//首先默认值为1，防止出错
    /**
    加载数据
    **/
    function loadData() {
        layui.use(['table','form'], function () {
            var condition = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            var dUrl = '../ProductSet/GetDataList?dataType=gxlist&condition=' + condition;

            var form = layui.form;
            //给table赋值
            table.render({
                elem: '#list'
                , url: dUrl //数据接口
                , title: '数据列表'
                , page: false //开启分页
                , even: true
                , id: "tData"
                , limits: [20, 50, 100]
                , limit: 20 //每页默认显示的数量
                , cols: [[
                    { field: 'cCode', title: '工序编码', width: 100 }
                    , { field: 'cName', title: '工序名称', width: 110 }
                    , { field: 'cMemo', title: '备注说明', width: 150 }
                    , { field: 'orderNum', title: '生产序号', width: 100 }
                    , { field: 'right', title: '操作', width: 100, align: 'center', toolbar: '#barDemo' }
                ]], done: function (res, curr, count) {
                    $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    TablePowerHide();
                }
            });

            //监听行工具事件
            table.on('tool(list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'edit') {
                    var title = data.cName+"-工序修改"  ;
                    var conditon = JSON.stringify(FormToJson("qForm"));
                    let url = "../ProductSet/UpdateGongXu?dataId=" +  data.id;
                    NewOpenPage(url, title, "80%", "90%", "tData", currPage, dUrl);

                } else if (layEvent == 'setu') {
                    let url = "../ProductSet/GongXuSetUser?gxCode=" + data.cCode;
                    NewOpenPage(url, data.cName + "-工序人员配置", "80%", "90%", "", currPage, dUrl);
                }
                else if (layEvent == 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        $.ajax({
                            url: "../Basic/DelCommonData",
                            type: "post",
                            data: { dataId: data.id },
                            success: function (data) {
                                if (data.result) {
                                    layer.msg("删除成功");
                                    obj.del();
                                } else {
                                    layer.msg(data.message);
                                }
                                loadData();
                            }
                        });
                        layer.close(index);
                    });
                }
            });
            // 监听开关事件（开关按钮）
            
            form.on('switch(switchTest)', function (data) {
                var cCode = data.elem.attributes['dataId'].nodeValue;
                var status = this.checked ? '1' : '0';
                $.ajax({
                    type: 'POST',
                    url: "../ProductSet/UpdateStatus",
                    data: { "cCode": cCode, "status": status },
                    beforeSend: function () {
                        index = layer.msg('正在切换中，请稍候', { icon: 16, time: false, shade: 0.8 });
                    },
                    error: function (data) {
                        console.log(data);
                        layer.msg('数据异常，操作失败！');
                    },
                    success: function (data) {
                        if (data.Result) {
                            layer.msg("修改完成");
                        } else {
                            layer.msg(data.Message);
                        }
                    },
                    dataType: 'JSON'
                });
            });


        });
    }
    /**
    更新数据
    **/
    function AddData() {
        InfoOpenPage("../ProductSet/UpdateGongXu?dataId=0", "新建工序", "85%", "90%");
   
    }

 

</script>
